package thread;

//new状态：安排了工作，还未开始行动
public class Demo16 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();

        Thread t = new Thread(() -> {
            while (true) {
                try {
                    System.out.println("main state=" + mainThread.getState());
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //打印状态，放在start之前调用
        System.out.println(t.getState());

        t.start();

        // 由于 t 线程是持续 while 循环, 因此 join 不会返回.
        // 观察主线程的状态, 就能看到 waiting.
        t.join();

        // System.out.println(t.getState());
    }
}
